home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
nroff1.zip
/
NROCMD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-07
|
17KB
|
654 lines
/*
* Command processor for NRO text processor
*
* Stephen L. Browning
* 5723 North Parker Avenue
* Indianapolis, Indiana 46220
*
* Ported to MS C 5.1
* by John Dudeck (jdudeck@polyslo.calpoly.edu) 11/25/90.
*/
#include <stdio.h>
#include "nro.h"
#include "nroxtrn.h"
char *skipbl();
char *skipwd();
comand(p)
char *p;
{
int ct, val;
int spval;
int index;
char argtyp;
char name[MAXLINE];
char macexp[MXMLEN];
ct = comtyp(p,macexp);
if (ct == UNKNOWN) {
printf("*** nro: unrecognized command %s\n",p);
return;
}
expesc(p,name);
val = getval(p,&argtyp);
switch (ct) {
case BO: /* bold face */
set(&dc.boval,val,argtyp,1,0,HUGE);
dc.cuval = dc.ulval = 0;
break;
case BP: /* begin page */
if(pg.lineno > 0) space(HUGE);
set(&pg.curpag,val,argtyp,pg.curpag+1,-HUGE,HUGE);
pg.newpag = pg.curpag;
break;
case BR: /* break */
brk();
break;
case BS: /* backspaces in output */
set(&dc.bsflg,val,argtyp,1,0,1);
break;
case CC: /* command character */
if (argtyp == '\r' || argtyp == '\n') dc.cmdchr = '.';
else dc.cmdchr = argtyp;
break;
case CE: /* center */
brk();
set(&dc.ceval,val,argtyp,1,0,HUGE);
break;
case CU: /* continuous underline */
set(&dc.cuval,val,argtyp,1,0,HUGE);
dc.ulval = dc.boval = 0;
break;
case DE: /* define macro */
defmac(p,sofile[dc.flevel]);
break;
case EF: /* even footer */
gettl(p,pg.efoot,&pg.eflim[0]);
break;
case EH: /* even header */
gettl(p,pg.ehead,&pg.ehlim[0]);
break;
case EN: /* end macro definition */
puts("***nro: missing .de command\n");
break;
case FI: /* fill */
brk();
dc.fill = YES;
break;
case FO: /* footer */
gettl(p,pg.efoot,&pg.eflim[0]);
gettl(p,pg.ofoot,&pg.oflim[0]);
break;
case HE: /* header */
gettl(p,pg.ehead,&pg.ehlim[0]);
gettl(p,pg.ohead,&pg.ohlim[0]);
break;
case IN: /* indenting */
set(&dc.inval,val,argtyp,0,0,dc.rmval-1);
dc.tival = dc.inval;
break;
case JU: /* justify */
dc.juval = YES;
break;
case LS: /* line spacing */
set(&dc.lsval,val,argtyp,1,1,HUGE);
break;
case M1: /* set topmost margin */
set(&pg.m1val,val,argtyp,2,0,HUGE);
break;
case M2: /* set second top margin */
set(&pg.m2val,val,argtyp,2,0,HUGE);
break;
case M3: /* set first bottom margin */
set(&pg.m3val,val,argtyp,2,0,HUGE);
pg.bottom = pg.plval - pg.m4val - pg.m3val;
break;
case M4: /* set bottom-most margin */
set(&pg.m4val,val,argtyp,2,0,HUGE);
pg.bottom = pg.plval - pg.m4val - pg.m3val;
break;
case MACRO: /* macro expansion */
maceval(p,macexp);
break;
case NE: /* need n lines */
brk();
if ((pg.bottom-pg.lineno+1) < (val*dc.lsval)) {
space(HUGE);
}
break;
case NF: /* no fill */
brk();
dc.fill = NO;
break;
case NJ: /* no justify */
dc.juval = NO;
break;
case NR: /* set number register */
p = skipwd(p);
p = skipbl(p);
if (!isalpha(*p)) {
puts("***nro: invalid or missing number register name\n");
}
else {
index = tolower(*p) - 'a';
p = skipwd(p);
val = getval(p,&argtyp);
set(&dc.nr[index],val,argtyp,0,-HUGE,HUGE);
}
break;
case OF: /* odd footer */
gettl(p,pg.ofoot,&pg.oflim[0]);
break;
case OH: /* odd header */
gettl(p,pg.ohead,&pg.ohlim[0]);
break;
case PC: /* page number character */
if (argtyp == '\r' || argtyp == '\n') dc.pgchr = EOS;
else dc.pgchr = argtyp;
break;
case PL: /* page length */
set(&pg.plval,val,argtyp,PAGELEN,
pg.m1val+pg.m2val+pg.m3val+pg.m4val+1,HUGE);
pg.bottom = pg.plval - pg.m3val - pg.m4val;
break;
case PO: /* page offset */
set(&pg.offset,val,argtyp,0,0,HUGE);
break;
case RM: /* right margin */
set(&dc.rmval,val,argtyp,PAGEWIDTH,dc.tival+1,HUGE);
break;
case SO: /* source file */
p = skipwd(p);
p = skipbl(p);
if (getwrd(p,name) == 0) break;
if (dc.flevel+1 >= NFILES) {
puts("***nro: .so commands nested too deeply\n");
exit(-1);
}
if ((sofile[dc.flevel+1] = fopen(name,"r")) == NULL) {
printf("***nro: unable to open %s\n",name);
exit(-1);
}
++dc.flevel;
break;
case SP: /* space */
set(&spval,val,argtyp,1,0,HUGE);
space(spval);
break;
case TI: /* temporary indent */
brk();
set(&dc.tival,val,argtyp,0,0,dc.rmval);
break;
case UL: /* underline */
set(&dc.ulval,val,argtyp,0,1,HUGE);
dc.cuval = dc.boval = 0;
break;
}
}
/*
* convert ascii character to decimal.
*/
atod(c)
char c;
{
return(((c < '0') || (c > '9')) ? -1 : c-'0');
}
/*
* end current filled line
*/
brk()
{
if(co.outp > 0) {
/* co.outbuf[co.outp] = '\r';
co.outbuf[co.outp + 1] = '\n';
co.outbuf[co.outp + 2] = EOS; */
co.outbuf[co.outp] = '\n';
co.outbuf[co.outp + 1] = EOS;
put(co.outbuf);
}
co.outp = 0;
co.outw = 0;
co.outwds = 0;
}
/*
* Collect macro definition from input stream
*/
colmac(p,d,i)
char *p, d[];
int i;
{
while (*p != EOS) {
if (i >= MXMLEN-1) {
d[i-1] = EOS;
return(ERR);
}
d[i++] = *p++;
}
d[i] = EOS;
return(i);
}
/*
* decodes nro command and returns its associated
* value.
*/
comtyp(p,m)
char *p;
char *m;
{
char c1, c2;
char macnam[MNLEN];
char *s;
p++;
/*
* First check to see if the command is a macro.
* If it is, truncate to two characters and return
* expansion in m. Note that upper and lower case
* characters are handled differently for macro names,
* but not for normal command names.
*/
getwrd(p,macnam);
macnam[2] = EOS;
if ((s = getmac(macnam)) != NULL) {